﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using Com.Framework;
using Com.Framework.Enc;
using Com.Library.DB.User;
using Com.Web.coffinegurunaru.AppLogic.Page;

namespace Com.Web.coffinegurunaru.member
{
	public partial class join_02 : WebPage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (this.IsPostBack)
			{
				byte n1GroupType = Request.Form["n1GroupType"].Parse((byte)2);

				if (n1GroupType == 3)
				{
					Response.Redirect("/member/join_02_1.aspx?se=" + Server.UrlEncode(Crypt.DESEncrypt(DateTime.Now.ToString())));
				}

				UserCreateArguments arg = new UserCreateArguments();
				arg.n1GroupType = 2;
				arg.n1UserLevel = 9;
				arg.IsLocalUser = Request.Form["IsLocalUser"].Parse("Y");
				arg.strUserID = Request.Form["strUserID"].Parse(string.Empty);
				arg.strMD5PWD = Crypt.MD5HashCrypt(Request.Form["strUserPWD1"].Parse(string.Empty));
				arg.strPersonalNo = "";
				arg.strUserName = Request.Form["strUserName"].Parse(string.Empty);
				arg.strEmail = Request.Form["strEmail1"].Parse(string.Empty) + "@" + Request.Form["strEmail2"].Parse(string.Empty);
				arg.IsEmail = Request.Form["IsEmail"].Parse(string.Empty);
				arg.n1Question = Request.Form["n1Question"].Parse((byte)0);
				arg.strAnswer = Request.Form["strAnswer"].Parse(string.Empty);
				arg.strPostNo = Request.Form["strPostNo1"].Parse(string.Empty) + "-" + Request.Form["strPostNo2"].Parse(string.Empty);
				arg.strAddress1 = Request.Form["strAddress1"].Parse(string.Empty);
				arg.strAddress2 = Request.Form["strAddress2"].Parse(string.Empty);
				arg.strHomePhone = Request.Form["strHomePhone1"].Parse(string.Empty) + "-" + Request.Form["strHomePhone2"].Parse(string.Empty) + "-" + Request.Form["strHomePhone3"].Parse(string.Empty);
				arg.strMobilePhone = Request.Form["strMobilePhone1"].Parse(string.Empty) + "-" + Request.Form["strMobilePhone2"].Parse(string.Empty) + "-" + Request.Form["strMobilePhone3"].Parse(string.Empty);
				arg.IsSMS = Request.Form["IsSMS"].Parse(string.Empty);
				arg.strBirthday = Request.Form["strBirthday1"].Parse(string.Empty) + "-" + Request.Form["strBirthday2"].Parse(string.Empty) + "-" + Request.Form["strBirthday3"].Parse(string.Empty);
				arg.IsLunar = Request.Form["IsLunar"].Parse("N");
				arg.n1JoinMotiveType = Request.Form["n1JoinMotiveType"].Parse((byte)0);
				arg.CodeSex = Request.Form["CodeSex"].Parse((byte)1);

				UserModel.Create(arg);
				Response.Redirect("/member/join_03.aspx?name=" + Server.UrlEncode( Request.Form["strUserName"].Parse(string.Empty) ) + "&se=" + Server.UrlEncode(Crypt.DESEncrypt(DateTime.Now.ToString())));
			}
			else
			{
				try
				{
					string enc = Crypt.DESDecrypt(Request.QueryString["se"].Parse(string.Empty));
					DateTime dt = Convert.ToDateTime(enc);
					if (dt.AddMinutes(10) < DateTime.Now)
					{
						Response.Redirect("/member/join_01.aspx");
					}
				}
				catch
				{
					Response.Redirect("/member/join_01.aspx");
				}
			}
		}
	}
}
